/**
 * Copyright 2019 [shujiang.yang], Inc. All rights reserved.
 * Email: 314938230@qq.com
 **/
define("pages/jbxx/jbxx_ksrs", [
		"../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
		"../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
		"../../plugins/artTemplate/artTemplate",
		"../../common/tools",
		"../../common/componts",
		"../../common/kss",
		"./jbxx_ksrs_form",
		"../../pages/jbxx/jbxx_ksrs_form.html.js"
	],
	function(require) {
		var componts = require("../../common/componts");
		var kss=require("../../common/kss");
		var jbxxDialog = require("./jbxx_ksrs_form");
		var businessTableId="businessTableId";
		var id;

		var getQueryDataGrid  = function(){
			return $('#'+businessTableId);
		};

		var initTable=function(){
			componts.initTable(businessTableId,{
				height:'615px',
				url:"/xyr/list",
				fit:true,
				columns :  [
					{
						field: 'oid',
						title: '序号',
						formatter: function(value, rowData, rowIndex){
							return '<input type="radio" name="ryRadio" id="ryRadio' + rowIndex + '" value="' + rowData.oid + '" />';
						}},
					{field : 'xm',title : '姓名',width : 80,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.xm==null?"":row.xm)+'>'+(row.xm==null?"":row.xm)+'</span>'}},
					{field : 'xbString',title : '性别',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.xbString==null?"":row.xbString)+'>'+(row.xbString==null?"":row.xbString)+'</span>'}},
					{field : 'csrq',title : '出生日期',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'mzString',title : '民族',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'whcdString',title : '文化程度',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'zyString',title : '职业',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'xzdString',title : '现居住地',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'rsrq',width : 150,title:'入所时间',sortable:'true',formatter: function(value,row,index){return '<span title='+value+'>'+value+'</span>'}},
					{field : 'ayString',title : '案别',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'jlrq',title : '拘留期限(日)',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field : 'bz',title : '备注',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(value==null?"":value)+'>'+(value==null?"":value)+'</span>'}},
					{field:'operate',title:'详细信息',align:'center',width : 60,/*width:$(this).width()*0.15,*/
						formatter:function(value, row, index){
							var str = '<a href="#" data-target="#ckPhoto" value="'+index+'" name="opera" data-toggle="modal" class="easyui-linkbutton"><img src="../../img/xq.png"></a>';
							return str;
							//return  '<button id="sh_add" onclick="add"  > 不通过</button>'
						}
					}
				] ,
				onLoadSuccess:function(data){
					if(data.total>0){
						getQueryDataGrid().datagrid("selectRow", 0);
						$("input[name='selectRadio1']")[0].checked = true;
					}

					$("a[name='opera']").each(function(){
						$(this).on('click',function(){
							var index=$(this).attr('value');
							var jbxx=data.rows[index];
							kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
						});
					});
				},
				//单击行选中取消事件
				onClickRow: function (rowIndex, rowData) {
					if(id!=rowData.id){
						$("input[name='selectRadio1']")[rowIndex].checked = true;
						getQueryDataGrid().datagrid("selectRow", rowIndex);
						id=rowData.id;
					}else if(id==rowData.id){
						getQueryDataGrid().datagrid("unselectRow",rowIndex);
						$("input[name='selectRadio1']")[rowIndex].checked = false;
						id="";
					}
					//加入列表中
					kss.zjryClick(rowData);
				},
				queryParams : {
					"processDefinitionKey":componts.getUrlParam('processDefinitionKey'),
					"taskDefinitionKey":componts.getUrlParam('taskDefinitionKey'),
					"pageSize" : function(){
						return getQueryDataGrid().datagrid("getPager").pagination("options").pageSize;
					},
					"pageIndex" : function(){
						return getQueryDataGrid().datagrid("getPager").pagination("options").pageNumber;
					}
				}
			})
			//页面高度自适应
			getQueryDataGrid().datagrid('resize',{
				height:($(window).height()-140)
			});
		}
		/**
		 * 数据列表刷新加载
		 */
		var loadDataGrid = function(){
			var formData = $(".awd-query-form").serializeObject();
			var queryParams = $.extend({},formData,{"state":"R2",
				"processDefinitionKey":componts.getUrlParam('processDefinitionKey'),
				"taskDefinitionKey":componts.getUrlParam('taskDefinitionKey'),
				"pageSize" : function(){
				return getQueryDataGrid().datagrid("getPager").pagination("options").pageSize;
			},
			"pageIndex" : function() {
				return getQueryDataGrid().datagrid("getPager").pagination("options").pageNumber;
			}});
			getQueryDataGrid().datagrid('clearSelections');
			getQueryDataGrid().datagrid('load',queryParams);
		};

		//绑定事件
		var bindAction=function(){
			//查询事件
			$(".query-btn").on("click",function(){
				loadDataGrid();
			});

			$(".awd-add-btn").on('click',function(){
				var selectedPerson = getQueryDataGrid().datagrid('getSelected');
				jbxxDialog.show(selectedPerson,loadDataGrid);
			});
		};

		var init = function(){
			initTable();
			bindAction();
			componts.initSelectPage(undefined);
			componts.initSelect(undefined,undefined,undefined);
		};
		init();
	});